package xkp.lesson4;

import java.nio.ByteBuffer;

public class TestBudder {
    public static void main(String[] args) {
        //1KB内存
        //默认处于写模式  postion为0  limit=capiticy=1024
        //在写模式下，limit与capiticy一致
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put((byte) 100);
        byteBuffer.put((byte) 100);
        byteBuffer.put((byte) 100);
        System.out.println(byteBuffer.position());
        System.out.println(byteBuffer.limit());
        System.out.println(byteBuffer.capacity());
        //转换模式 转换为读模式
        byteBuffer.flip();//在执行flip()方法后，postion变为0  limit变为原有postion的值，capticy保持不变
        //表示在读模式下最多读取原有存储的数据量
        System.out.println(byteBuffer.position());
        System.out.println(byteBuffer.limit());
        System.out.println(byteBuffer.capacity());
        //
        while(byteBuffer.hasRemaining()){
            //每读一次，position向后移动
           byte b = byteBuffer.get();
            System.out.println(b);
        }
    }
}
